package com.ruoyi.system.controller;

import com.ruoyi.common.utils.SecurityUtils;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ZnProfitHistory;
import com.ruoyi.system.service.IZnProfitHistoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 盘点计算记录Controller
 * 
 * @author nexiaozi
 * @date 2022-10-19
 */
@RestController
@RequestMapping("/system/profithistory")
public class ZnProfitHistoryController extends BaseController
{
    @Autowired
    private IZnProfitHistoryService znProfitHistoryService;

    /**
     * 查询盘点计算记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:profithistory:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZnProfitHistory znProfitHistory)
    {
        znProfitHistory.setTenantId(SecurityUtils.getTenantId());
        startPage();
        List<ZnProfitHistory> list = znProfitHistoryService.selectZnProfitHistoryList(znProfitHistory);
        return getDataTable(list);
    }

    /**
     * 导出盘点计算记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:profithistory:export')")
    @Log(title = "盘点计算记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZnProfitHistory znProfitHistory)
    {
        znProfitHistory.setTenantId(SecurityUtils.getTenantId());
        List<ZnProfitHistory> list = znProfitHistoryService.selectZnProfitHistoryList(znProfitHistory);
        ExcelUtil<ZnProfitHistory> util = new ExcelUtil<ZnProfitHistory>(ZnProfitHistory.class);
        util.exportExcel(response, list, "盘点计算记录数据");
    }

    /**
     * 获取盘点计算记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:profithistory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(znProfitHistoryService.selectZnProfitHistoryById(id));
    }

    /**
     * 新增盘点计算记录
     */
    @PreAuthorize("@ss.hasPermi('system:profithistory:add')")
    @Log(title = "盘点计算记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZnProfitHistory znProfitHistory)
    {
        return toAjax(znProfitHistoryService.insertZnProfitHistory(znProfitHistory));
    }

    /**
     * 修改盘点计算记录
     */
    @PreAuthorize("@ss.hasPermi('system:profithistory:edit')")
    @Log(title = "盘点计算记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZnProfitHistory znProfitHistory)
    {
        return toAjax(znProfitHistoryService.updateZnProfitHistory(znProfitHistory));
    }

    /**
     * 删除盘点计算记录
     */
    @PreAuthorize("@ss.hasPermi('system:profithistory:remove')")
    @Log(title = "盘点计算记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(znProfitHistoryService.deleteZnProfitHistoryByIds(ids));
    }
}
